package cn.com.zonesion.rfiddemo.fragment.microwavefragment;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cn.com.zonesion.rfiddemo.R;
import cn.com.zonesion.rfiddemo.base.BaseFragment;

public class MicrowaveReadFragment extends BaseFragment {
    /**
     *编组 EditText
     */
    @BindView(R.id.edit_read_mars)
    EditText editReadMars;
    /**
     * 信道
     */
    @BindView(R.id.tty_spiner_read_channel)
    Spinner ttySpinerReadChannel;
    /**
     *寻卡操作ListView
     */
    @BindView(R.id.listview_search_cards)
    ListView listviewSearchCards;
    /**
     * 标签
     */
    @BindView(R.id.tty_spiner_read_label)
    Spinner ttySpinerReadLabel;
    /**
     * 操作记录ListView
     */
    @BindView(R.id.listview_record)
    ListView listviewRecord;
    /**
     * 阅读操作“写入”
     */
    @BindView(R.id.edit_read_write)
    EditText edit_read_write;
    /**
     * 数据块
     */
    @BindView(R.id.tty_spinner_read_data)
    Spinner ttySpinnerReadData;
    /**
     * Unbinder对象，用来解除ButterKnife与Fragment对象的绑定
     */
    /**
     * 信道数组，用来存放常用数组
     */
    private String[] channelArray;
    /**
     * 数据块编号数组，用来存放常用数组
     */
    private String[] dataNumberArray;
    /**
     * 对应的信道
     */
    private int channel;
    /**
     * 对应的数据块编号
     */
    private int dataNumber;

    private Unbinder unbinder;

    @Override
    public View initView() {
        View view = View.inflate(mContext, R.layout.read_microwave_item, null);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void initData() {
        super.initData();
        inti();
    }

    private void inti(){
        channelArray = getResources().getStringArray(R.array.channel);
        dataNumberArray = getResources().getStringArray(R.array.datablocknumber);
        ttySpinerReadChannel.setAdapter(new ArrayAdapter<>(getActivity(),R.layout.spinner_layout,R.id.textView,channelArray));
        ttySpinnerReadData.setAdapter(new ArrayAdapter<>(getActivity(),R.layout.spinner_layout,R.id.textView,dataNumberArray));
        //信道
        ttySpinerReadChannel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                channel = Integer.parseInt(channelArray[position]);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        //数据块
        ttySpinnerReadData.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                dataNumber = Integer.parseInt(dataNumberArray[position]);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }
    @Override
    public void onDestroyView() {
        //解除ButterKnife与icApplicationFragment的绑定
        unbinder.unbind();
        super.onDestroyView();
    }
    @OnClick({R.id.btn_read_mars_read,R.id.btn_read_channel_write,R.id.btn_read_clear,
            R.id.btn_search_cards,R.id.btn_read_elimin,R.id.btn_read_read,R.id.btn_read_write})
    public void onClick(View view){
        switch (view.getId()) {
            case  R.id.btn_read_mars_read:

                break;
            case R.id.btn_read_channel_write:

                break;
            case R.id.btn_read_clear:

                break;
            case R.id.btn_search_cards:

                break;
            case R.id.btn_read_elimin:

                break;
            case R.id.btn_read_read:

                break;
            case R.id.btn_read_write:

                break;
        }
    }
}
